import uuid
from django.db.models import QuerySet


# 获取去除短横线36位UUID
def FormatUUID() -> str:
    return str(uuid.uuid4()).replace("-", "")

# 返回列表字典
def to_dict_list(data: QuerySet):
    model_list = []
    for model in data:
        if hasattr(model, 'to_dict'):
            model_list.append(model.to_dict())
    return model_list

# 返回字典列表
def to_json(data: QuerySet):
    return list(data.values())

# 判断字符串是否为空和None
def IsNoneOrWhitespace(item) -> bool:
    if item is None:
        return True
    if len(item) == 0:
        return True
    if str(item).isspace():
        return True
    return False

# 解析前端传入的BODY参数
def GetRequestBody():
    pass

# 移除字典空字符串或None值
def remove_empty_keys(dictionary) -> dict:
    return dict(filter(lambda item: item[1] != '' and item[1] is not None, dictionary.items()))


